﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using University.Workshop.Presenters.WaterPurchase;

namespace University.Workshop.Presentation.WaterPurchase
{
    /// <summary>
    /// Interaction logic for SearchWaterPurchase.xaml
    /// </summary>
    public partial class SearchWaterPurchase : Page, ISearchWaterPurchaseView
    {
        PresenterSearchWaterPurchase pSearchWaterPurchase;
        List<char> fechaCaracteres = new List<char>();


        public SearchWaterPurchase()
        {
            InitializeComponent();
            pSearchWaterPurchase = new PresenterSearchWaterPurchase(this);
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            App.Current.MainWindow.Title = "Buscar Compra";
        }

        private void SearchBtn_Click(object sender, RoutedEventArgs e)
        {
            pSearchWaterPurchase.SearchWaterPurchase();
        }

        

        #region ISearchWaterPurchaseView Members

        public ICollection<Model.WaterPurchase> WaterPurchaseFinded
        {
            get
            {
                if (WaterPurchaseFindedDgv.ItemsSource == null)
                    new List<Model.WaterPurchase>();
                return (ICollection<Model.WaterPurchase>)WaterPurchaseFindedDgv.ItemsSource;
            }
            set
            {
                WaterPurchaseFindedDgv.ItemsSource = null;
                WaterPurchaseFindedDgv.ItemsSource = value;
            }
        }

        public void NotifyErrorMessage(string MessageValue)
        {
            MessageBox.Show(App.Current.MainWindow, MessageValue, "Error!!!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.RightAlign);
        }

        public void NotifySystemMessage(string p)
        {
            //MessageBox.Show(App.Current.MainWindow, MessageValue, "Atencion!!!", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK, MessageBoxOptions.RightAlign);
        }


        private void ShowUserBtn_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new WaterPurchase.PageReadView((Model.WaterPurchase)WaterPurchaseFindedDgv.SelectedItem));
        }

        private void ModifyUserBtn_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new WaterPurchase.PageModifyView((Model.WaterPurchase)WaterPurchaseFindedDgv.SelectedItem));
        }

        public string LicencePlate
        {
            get
            {
                return LicencePlateTxBx.Text;
            }
            set
            {
                LicencePlateTxBx.Text = value;
            }
        }

        public DateTime DatePurchase
        {
            get
            {
                return DateTime.Parse(DatePurchaseDpck.Text);
            }
            set
            {
                DatePurchaseDpck.Text = value.ToString();
            }
        }

        public string Courtesy
        {
            get
            {
                return CourtesyDdl.SelectionBoxItem.ToString();
            }
            set
            {
                //CourtesyChk.IsChecked = value;
            }
        }

        public bool NotifyConfirmationMessage(string MessageValue)
        {
            return MessageBox.Show(App.Current.MainWindow,
                MessageValue,
                "Atención!!!",
                MessageBoxButton.YesNo,
                MessageBoxImage.Information,
                MessageBoxResult.Yes,
                MessageBoxOptions.RightAlign) == MessageBoxResult.Yes;
        }

        public void OpenDisableUserPopUp(Model.WaterPurchase u)
        {
        }

        public Model.WaterPurchase WaterPurchaseSelected
        {
            get { return (Model.WaterPurchase)WaterPurchaseFindedDgv.SelectedItem; }
        }



        public void HideDisableUser()
        {

        }

        public void GoToModifyUser(Model.WaterPurchase user)
        {
            //this.NavigationService.Navigate(new PageModifyView(user)); 
        }

        #endregion

        private void CantCupyPasteOrCut(object sender, CanExecuteRoutedEventArgs e)
        {
            if (e.Command == ApplicationCommands.Copy)
                e.Handled = true;
            if (e.Command == ApplicationCommands.Cut)
                e.Handled = true;
            if (e.Command == ApplicationCommands.Paste)
                e.Handled = true;
        }


        private void PersonNamesTxt_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            string temporal = ((TextBox)sender).Text + e.Text;
            foreach (char ch in e.Text)
            {
                e.Handled = !(char.IsLetter(ch));
            }
        }

        private void UsernamesTxt_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Space)
            {
                e.Handled = true;
            }
        }

        private void UsernameTxt_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            string temporal = ((TextBox)sender).Text + e.Text;
            foreach (char ch in e.Text)
            {
                e.Handled = !(char.IsLetterOrDigit(ch) || ch.Equals('_'));
            }
        }

        private void DatePurchaseDpck_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            e.Handled = true;
        }
    }
}
